using System.Collections.Generic;
using MEC;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System;

namespace hatbox_hack
{
    class FXMgr_ : MonoBehaviour
    {
        public static FXMgr_ I;

        public GameObject gameObject;

        public ResistanceBar rb;

        public SerializedObjectPool<ResistanceBar> ResistanceBarPool;

        public static FXMgr_ createFXMgr_()
        {
            // 绑定
            GameObject g = new GameObject();
            g.name = "HH_FXMgr_";
            FXMgr_ r = g.AddComponent<FXMgr_>();
            r.gameObject = g;
            g.SetActive(true);
            g.transform.position = new Vector3(0, 114514, 0);

            // no die
            DontDestroyOnLoad(g);
            return r;
        }

        public void Awake()
        {
            GameObjects.hatboxHack.log("FXMGR_ AWAKE");
            FXMgr_.I = this;
        }

        public void Start()
        {
            GameObjects.hatboxHack.log("FXMGR_ START");
            rb = ResistanceBar.CreateResistanceBar();

            rb.transform.SetParent(base.transform);

            this.ResistanceBarPool = new SerializedObjectPool<ResistanceBar>(rb);
        }

        public void OnSceneAboutToChange()
        {
            ResistanceBarPool.DisableAllAndSetParent(base.transform);
        }

        public ResistanceBar CreateResistanceBar(Actor a)
        {
            ResistanceBar resistanceBar = ResistanceBarPool.Get();
            resistanceBar.Init(a);
            return resistanceBar;
        }

        public void RemoveResistanceBar(ResistanceBar p)
        {
            p.transform.SetParent(base.transform);
            ResistanceBarPool.DisableObj(p);
        }

        public static void CopyRectTransformProperties(RectTransform source, RectTransform target)
        {
            // 复制源RectTransform的属性到目标RectTransform
            RectTransformUtility.FlipLayoutOnAxis(
                target,
                (int)RectTransform.Axis.Horizontal,
                false,
                false
            );

            target.localScale = source.localScale;
            target.localPosition = source.localPosition;
            target.anchorMin = source.anchorMin;
            target.anchorMax = source.anchorMax;
            target.offsetMin = source.offsetMin;
            target.offsetMax = source.offsetMax;
            target.pivot = source.pivot;
            target.rotation = source.rotation;
        }
    }
}
